import java.io.*;
import org.apache.poi.xssf.usermodel.*;
public class ReadXLSX
{
public static void main(String args[])
{
StringBuffer data = new StringBuffer();
try {
File f = new File("D:/project/src/java/quotes/tcsbo.csv");
if(f.exists())
{
System.out.println("Exists");
//f.delete();
}
FileOutputStream fos = new FileOutputStream(f);
// POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("C:/testing/1.xlsx"));
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream("D:/project/src/java/quotes/tcsbo.xlsx"));
XSSFSheet sheet = wb.getSheetAt(0);
XSSFRow row;
XSSFCell cell;
int rows; // No of rows
rows = sheet.getPhysicalNumberOfRows();
int cols = 0; // No of columns
int tmp = 0;
// This trick ensures that we get the data properly even if it doesn't start from first few rows
for(int i = 0; i < 10&&i < rows; i++) {
row = sheet.getRow(i);
if(row != null) {
tmp = sheet.getRow(i).getPhysicalNumberOfCells();
if(tmp > cols) cols = tmp;
}
}
for(int r = 0; r < rows; r++) {
row = sheet.getRow(r);
data.append("\n");
if(row != null) {
for(int c = 0; c < cols; c++) {
cell = row.getCell((short)c);
/* if(cell.getCellType()==2)
{
data.append("="+cell+",");
}
else{*/
if(cell.getCellType()== 2)
    data.append(cell.getCachedFormulaResultType()+",");
else
    data.append(cell+",");
// }
if(cell != null) {
// Your code here
}
}
}
}
fos.write(data.toString().getBytes());
} catch(Exception ioe) {
ioe.printStackTrace();
}
}
}